<%@ page language="java" import="java.util.*,java.text.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<base target="_self">
  <head>
    
    <title>班级课表</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<script type="text/javascript" src="<%=path%>/js/jQuery/jquery-1.6.min.js"></script>
	<script type="text/javascript">
	 	$(document).ready(function(){
	 		var nextvalue;
	 		var initClass = window.dialogArguments;
	 		var initClassSplit = initClass.split("-");
	 		var initClassId = initClassSplit[0];
	 		var initClassName = initClassSplit[1];
	 		//alert(initClassId+"-"+initClassName);
	 		var par =new Array(6);
	 		par[0]=0;//系院ID
	 		par[1]=0;//专业ID
	 		par[2]=initClassId;//班级ID
	 		par[3]='专业名';
	 		par[4]=initClassName;
	 		par[5]='课表名';
	 		$("#PrintName").val(initClassName);
	 		//$("#title").val($("#scheduleName").val());
	 		$("#printRemark").val($("#remark").html());
	 		$("#printTime").val($("#time").html());
	 		var newwin = par[0]+","+par[1]+","+par[2]+","+par[3]+","+par[4]+","+par[5];
	 		
	 		var flag = "";
	 		//var newwin = window.showModalDialog("classCondition.jsp", "", "dialogTop:300px;dialogWidth:600px;dialogHeight:150px;location=no; dialogLeft:300px;modal=yes");
	 		if(initClassId==""||initClassId=="undifined"||isNaN(initClassId)){//系院ID+专业ID+班级ID("all")+专业名+班级名+课表名
	 			alert("没有得到班级信息！");
	 			return false;
	 		}else{
	 			//par = newwin.split(",");
	 			//$("#professionalName").html(par[3]);
	 			$("#classesName").html(par[4]);
	 			//$("#scheduleName").html(par[5]);
	 			$.ajax({
						url: '/schedule/queryPaikeByClassId',
						data: "flag="+par[2]+","+par[5],//newwin+",-"
						type: "POST",
						success:function(data){
								$(data.root).each(function(index,scheduleByClass){
									//alert(scheduleByClass.classId);
									var classId = scheduleByClass.classId;
									if(scheduleByClass.j01.classId!=0){
										var j01 = scheduleByClass.j01;
										$("#j01").html("<input type = 'hidden' value ='j01-"+j01.scheduleId+"' /><div align ='center' id='courses'>"+j01.courseName+"&nbsp; ("+j01.totalTime+")<br>(1-"+j01.weeks+")"+j01.teacherName+"&nbsp;"+j01.classroomName+"</div>");
									};
									var j02 = scheduleByClass.j02;
									if(j02.classId!=0){
										$("#j02").html("<input type = 'hidden' value ='j02-"+j02.scheduleId+"' /><div align ='center' id='courses'>"+j02.courseName+"&nbsp; ("+j02.totalTime+")<br>(1-"+j02.weeks+")"+j02.teacherName+"&nbsp;"+j02.classroomName+"</div>");
									};
									var j03 = scheduleByClass.j03;
									if(j03.classId!=0){
										$("#j03").html("<input type = 'hidden' value ='j03-"+j03.scheduleId+"' /><div align ='center' id='courses'>"+j03.courseName+"&nbsp;("+j03.totalTime+")<br>(1-"+j03.weeks+")"+j03.teacherName+"&nbsp;"+j03.classroomName+"</div>");
									};
									var j04 = scheduleByClass.j04;
									if(j04.classId!=0){
										$("#j04").html("<input type = 'hidden' value ='j04-"+j04.scheduleId+"' /><div align ='center' id='courses'>"+j04.courseName+"&nbsp; ("+j04.totalTime+")<br>(1-"+j04.weeks+")"+j04.teacherName+"&nbsp;"+j04.classroomName+"</div>");
									};
									var j05 = scheduleByClass.j05;
									if(j05.classId!=0){
										$("#j05").html("<input type = 'hidden' value ='j05-"+j05.scheduleId+"' /><div align ='center' id='courses'>"+j05.courseName+"&nbsp; ("+j05.totalTime+")<br>(1-"+j05.weeks+")"+j05.teacherName+"&nbsp;"+j05.classroomName+"</div>");
									};
									var j06 = scheduleByClass.j06;
									if(j06.classId!=0){
										$("#j06").html("<input type = 'hidden' value ='j06-"+j06.scheduleId+"' /><div align ='center' id='courses'>"+j06.courseName+"&nbsp; ("+j06.totalTime+")<br>(1-"+j06.weeks+")"+j06.teacherName+"&nbsp;"+j06.classroomName+"</div>");
									};
									var j07 = scheduleByClass.j07;
									if(j07.classId!=0){
										$("#j07").html("<input type = 'hidden' value ='j07-"+j07.scheduleId+"' /><div align ='center' id='courses'>"+j07.courseName+"&nbsp; ("+j07.totalTime+")<br>(1-"+j07.weeks+")"+j07.teacherName+"&nbsp;"+j07.classroomName+"</div>");
									};
									var j08 = scheduleByClass.j08;
									if(j08.classId!=0){
										$("#j08").html("<input type = 'hidden' value ='j08-"+j08.scheduleId+"' /><div align ='center' id='courses'>"+j08.courseName+"&nbsp; ("+j08.totalTime+")<br>(1-"+j08.weeks+")"+j08.teacherName+"&nbsp;"+j08.classroomName+"</div>");
									};
									var j09 = scheduleByClass.j09;
									if(j09.classId!=0){
										$("#j09").html("<input type = 'hidden' value ='j09-"+j09.scheduleId+"' /><div align ='center' id='courses'>"+j09.courseName+"&nbsp; ("+j09.totalTime+")<br>(1-"+j09.weeks+")"+j09.teacherName+"&nbsp;"+j09.classroomName+"</div>");
									};
									var j10 = scheduleByClass.j10;
									if(j10.classId!=0){
										$("#j10").html("<input type = 'hidden' value ='j10-"+j10.scheduleId+"' /><div align ='center' id='courses'>"+j10.courseName+"&nbsp; ("+j10.totalTime+")<br>(1-"+j10.weeks+")"+j10.teacherName+"&nbsp;"+j10.classroomName+"</div>");
									};
									var j11 = scheduleByClass.j11;
									if(j11.classId!=0){
										$("#j11").html("<input type = 'hidden' value ='j11-"+j11.scheduleId+"' /><div align ='center' id='courses'>"+j11.courseName+"&nbsp; ("+j11.totalTime+")<br>(1-"+j11.weeks+")"+j11.teacherName+"&nbsp;"+j11.classroomName+"</div>");
									};
									var j12 = scheduleByClass.j12;
									if(j12.classId!=0){
										$("#j12").html("<input type = 'hidden' value ='j12-"+j12.scheduleId+"' /><div align ='center' id='courses'>"+j12.courseName+"&nbsp; ("+j12.totalTime+")<br>(1-"+j12.weeks+")"+j12.teacherName+"&nbsp;"+j12.classroomName+"</div>");
									};
									var j13 = scheduleByClass.j13;
									if(j13.classId!=0){
										$("#j13").html("<input type = 'hidden' value ='j13-"+j13.scheduleId+"' /><div align ='center' id='courses'>"+j13.courseName+"&nbsp; ("+j13.totalTime+")<br>(1-"+j13.weeks+")"+j13.teacherName+"&nbsp;"+j13.classroomName+"</div>");
									};
									var j14 = scheduleByClass.j14;
									if(j14.classId!=0){
										$("#j14").html("<input type = 'hidden' value ='j14-"+j14.scheduleId+"' /><div align ='center' id='courses'>"+j14.courseName+"&nbsp; ("+j14.totalTime+")<br>(1-"+j14.weeks+")"+j14.teacherName+"&nbsp;"+j14.classroomName+"</div>");
									};
									var j15 = scheduleByClass.j15;
									if(j15.classId!=0){
										$("#j15").html("<input type = 'hidden' value ='j15-"+j15.scheduleId+"' /><div align ='center' id='courses'>"+j15.courseName+"&nbsp; ("+j15.totalTime+")<br>(1-"+j15.weeks+")"+j15.teacherName+"&nbsp;"+j15.classroomName+"</div>");
									};
									var j16 = scheduleByClass.j16;
									if(j16.classId!=0){
										$("#j16").html("<input type = 'hidden' value ='j16-"+j16.scheduleId+"' /><div align ='center' id='courses'>"+j16.courseName+"&nbsp; ("+j16.totalTime+")<br>(1-"+j16.weeks+")"+j16.teacherName+"&nbsp;"+j16.classroomName+"</div>");
									};
									var j17 = scheduleByClass.j17;
									if(j17.classId!=0){
										$("#j17").html("<input type = 'hidden' value ='j17-"+j17.scheduleId+"' /><div align ='center' id='courses'>"+j17.courseName+"&nbsp;("+j17.totalTime+")<br>(1-"+j17.weeks+")"+j17.teacherName+"&nbsp;"+j17.classroomName+"</div>");
									};
									var j18 = scheduleByClass.j18;
									if(j18.classId!=0){
										$("#j18").html("<input type = 'hidden' value ='j18-"+j18.scheduleId+"' /><div align ='center' id='courses'>"+j18.courseName+"&nbsp; ("+j18.totalTime+")<br>(1-"+j18.weeks+")"+j18.teacherName+"&nbsp;"+j18.classroomName+"</div>");
									};
									var j19 = scheduleByClass.j19;
									if(j19.classId!=0){
										$("#j19").html("<input type = 'hidden' value ='j19-"+j19.scheduleId+"' /><div align ='center' id='courses'>"+j19.courseName+"&nbsp; ("+j19.totalTime+")<br>(1-"+j19.weeks+")"+j19.teacherName+"&nbsp;"+j19.classroomName+"</div>");
									};
									var j20 = scheduleByClass.j20;
									if(j20.classId!=0){
										$("#j20").html("<input type = 'hidden' value ='j20-"+j20.scheduleId+"' /><div align ='center' id='courses'>"+j20.courseName+"&nbsp; ("+j20.totalTime+")<br>(1-"+j20.weeks+")"+j20.teacherName+"&nbsp;"+j20.classroomName+"</div>");	
									};
									//alert(j01.classId+"-"+j01.classroomId+"-"+j01.teacherId+"-"+j01.courseId);
								});        
						}
					});  
	 		}
	 		var td = $('#data TD').not("#data TD:first-child");
			    td.mousedown(function(e){ 
			         scheduleidd= $(this).find('input').val();
			         //alert(scheduleidd); 
					 if(e.which==3){ // 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键  
					 	if($(this).html()!=""){
						 	var truthBeTold = window.confirm("确认删除吗？"); 
							if (truthBeTold) { 
								$(this).html("");
								var flag1 = $("#scheduleName").text()+"-"+par[2]+"@";
								flag1 += scheduleidd+",";
								//alert(flag1);
					            $.ajax({
									url: "/schedule/deletePaiKe",
									data: "flag="+flag1,
									type: "POST",
									success:function(data){
										if(data!=null){
											//alert('删除成功！');
										}
									}
								});  
								return false;
							} else{
								return false;
							}
						}
					 } 
				 }); 
				  
			var showFlag = false;//判断是否显示以前的那个值
			td.click(function() {
				nextvalue = window.showModalDialog("choiceCourse.jsp", newwin, "dialogTop:200px;dialogWidth:640px;dialogHeight:400px; dialogLeft:200px;scroll=yes");
				//课称名称-老师名称-教室名称-总课时-scheduleId-weeks(有多少周)
				if(nextvalue==null||""==nextvalue){
					return false;
				}else{
					var oldValue = $(this)[0].innerHTML;//更新之前的值
					var jall = nextvalue.split(",");
					var scheduleId = jall[4];
					var courseId;
					var courseName = jall[0];
					var calssId;
					var className;
					var classroomId;
					var classroomName = jall[2];
					var teacherId;
					var teacherName = jall[1];
					var totalTime = jall[3];
					var weeks = jall[5];
					var jj = $(this).attr("id");
					//alert($(this).attr("id")+"-"+scheduleId);
					//$(this).html("<input type = 'hidden' value ='"+$(this).attr("id")+"-"+scheduleId+"' /><div align ='center' id='courses'>"+courseName+"&nbsp;（"+totalTime+"）<br>"+teacherName+"&nbsp;"+classroomName+"</div>");
					var flag1 = $("#scheduleName").text()+"-"+par[2]+"@";
					flag1 += $(this).attr("id")+"-"+scheduleId+",";
					//alert(flag1);
		            $.ajax({
						url: "/schedule/queryPaiKe",
						data: "flag="+flag1,
						type: "POST",
						success:function(data){
							var valuere = data.root[0];
							//alert(valuere);
							if(""!=valuere){
								 var truthBeTold = window.confirm(valuere+"是否继续执行？");
								 if (!truthBeTold) {
									 $("#"+jj).html(oldValue);//返回原来的值
									//history.go(0);
									//$("#reload").href=window.location.href+"&random="+Math.random();
									//reload.click();
								 	return false;
								 }
							}
							$.ajax({
								url: "/schedule/addPaiKe",
								data: "flag="+flag1,
								type: "POST",
								success:function(data){
									return true;
									}
							 });
						}
					});
					$("#"+jj).html("<input type = 'hidden' value ='"+$(this).attr("id")+"-"+scheduleId+"' /><div align ='center' id='courses'>"+courseName+"&nbsp;（"+totalTime+"）<br>（1-"+weeks+"）"+teacherName+"&nbsp;"+classroomName+"</div>");//更新选择的课程
				}
			});
			
			$("#reset").click(function(){//重置
				   var truthBeTold = window.confirm("确认重置吗？重置后该班级的课表将没有记录"); 
				   if (truthBeTold) { 
					   flag = $("#scheduleName").text()+"-"+par[2]+"@";
					   $("input[type=hidden]").each(function(index,schedule){
					   		flag += $(this).attr("value")+",";
					   });	
					   //alert(flag);
			           $.ajax({
							url: "/schedule/deletePaiKe",
							data: "flag="+flag,
							type: "POST",
							success:function(data){
								window.location.reload();
								td.html("");
								alert("重置成功！");
							}
						}); 
					}else{
					 	return false;
					} 
				}); 
			$("#submit2").click(function(){//提交
			       //标题+班级Id
				   flag = $("#scheduleName").text()+"-"+par[2]+"@";
				   $("input[type=hidden]").each(function(index,schedule){
				   		flag += $(this).attr("value")+",";
				   });	
				   //alert(flag);
		           $.ajax({
						url: "/schedule/addPaiKe",
						data: "flag="+flag,
						type: "POST",
						success:function(data){
							window.location.reload();
							alert("保存成功！");
						}
					});  
			});
			$("#Submit3").click(function(){//打印
	 			var values="";
	 			if(td[0].innerText==""){
	 				values = "-";
	 			}else{
	 				values = td[0].innerText;
	 			}
	 			for (i = 1; i < 20; i++){
	 				if(td[i].innerText==""){
	 					values +="@!-";
	 				}else{
	 					values += "@!"+td[i].innerText;
	 				}
	 			}

	 			//alert(values);
	 			$("#Print").val(values);
				$("#form2").submit();  
				//var newwin = window.showModelessDialog("ReaderPrint.jsp", 1+","+classroomId+","+classroomName, "dialogTop:500px;dialogWidth:800px;dialogHeight:500px;location=no;resizable:yes; dialogLeft:300px;modal=yes"); 
			});
		});
	</script>

<body leftmargin=20 topmargin=20  bottommargin="1" bgcolor="#DFE8F6">
<form name="form1" id="form1" method="post" action="/schedule/addSchedule" style="margin-bottom:2px">
  <div align="center" id="buttondiv">
  <TABLE id="data" width=100% height=96% border="0" bordercolor="#FF0000" cellspacing="1"  >
    <TR bgcolor="FFFFFF">
      <% Date dt = new Date(); int year =1900+dt.getYear(); %>
      <TH height='15' colspan="6" id=""><label id="scheduleName">湖南文理学院
		<select name='season' id='season'>
			<option><%=year%>年度春（夏）</option>
			<option><%=year%>年度秋（冬）</option>
			<option><%=year+1%>年度春（夏）</option>
			<option><%=year+1%>年度秋（冬）</option>
			<option><%=year+2%>年度春（夏）</option>
			<option><%=year+2%>年度秋（冬）</option>
		</select>
		学期分班课程表</label></TH>
      
      </TR>
      
      <TR bgcolor="FFFFFF">
      <TH height='15' colspan="6" id=""><span style="float:left" ><label id="professionalName"></label></span><span style="float:right">班级：<label id="classesName"></label>&nbsp;&nbsp;&nbsp;</span></TH>
      </TR>
    <TR bgcolor="FFFFFF" height="10%">
      <TH width="10%" height='40' id="">节数/
      星期</TH>
    <TH width="18%">星期一</TH>
    <TH width="18%">星期二</TH>
    <TH width="18%">星期三</TH>
    <TH width="18%">星期四</TH>
    <TH width="18%">星期五</TH>
    </TR>
    <TR id="星期一" bgcolor="FFFFFF" height="15%">
      <TD><div align="center">一二节</div></TD>
      <TD id="j01" align="center"></TD>
      <TD id="j05" align="center"></TD>
      <TD id="j09"></TD>
      <TD id="j13"></TD>
      <TD id="j17"></TD>
    </TR>
    <TR id="星期二" bgcolor="FFFFFF" height="15%">
      <TD><div align="center">三四节</div></TD>
      <TD id="j02"></TD>
      <TD id="j06"></TD>
    <TD id="j10"></TD>
    <TD id="j14"></TD>
    <TD id="j18"></TD>
    </TR>
    <TR id="星期三" bgcolor="FFFFFF" height="15%">
      <TD><div align="center">五六节</div></TD>
      <TD id="j03"></TD>
      <TD id="j07"></TD>
    <TD id="j11"></TD>
    <TD id="j15"></TD>
    <TD id="j19"></TD>
    </TR>
    <TR id="星期四" bgcolor="FFFFFF" height="15%">
      <TD><div align="center">七节</div></TD>
      <TD id="j04"></TD>
      <TD id="j08"></TD>
    <TD id="j12"></TD>
    <TD id="j16"></TD>
    <TD id="j20"></TD>
    </TR>
    <TR bgcolor="FFFFFF" height="10%">
    <% DateFormat df = new SimpleDateFormat("yyyy年MM月dd日"); %>
      <TD colspan="6"><span id ="remark" style="float:left">备注：1.第8-9节（冬)19:00-20:40  (夏)19:30-21:10</span><span id="time" style="float:right"><%=df.format(new Date())%></span></TD>
     </TR>
    <TR bgcolor="FFFFFF" height="10%">
      <TD width=100% colspan="6" align="center">
	  	<input type="reset" name="reset" id="reset" style="background:#7C97E4" value="重置">  
        <input type="hidden" style="background:#7C97E4" name="Submit2" id="submit2" value="提交" > 
        <input type="button" style="background:#7C97E4" name="Submit3" id = "Submit3"  value="导出课表" >
       </TD>
    </TR>
  </TABLE>
  </div>
</form>
<form id="form2" name="form2" method="post" action="./ReaderPrint.jsp">
        <input type="hidden" name="Print" id="Print" >
        <input type="hidden" name="PrintName" id="PrintName" >
        <input type="hidden" name="title" id="title" >
        <input type="hidden" name="printRemark" id="printRemark" >
        <input type="hidden" name="printTime" id="printTime" >
 </form>
<div id="foot" style="background:white;text-align: center;"> </div>
</BODY>
</html>